package com.gxa.medical.service.impl;

import com.gxa.medical.exception.BusinessException;
import com.gxa.medical.exception.ExceptionCode;
import com.gxa.medical.mapper.DoctorAccountMapper;
import com.gxa.medical.pojo.DoctorAccount;
import com.gxa.medical.service.DoctorAccountService;
import com.gxa.medical.service.DoctorService;
import com.gxa.medical.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Yang Kai
 * @Date: 2022/06/09/10:07
 * @Description:
 */

@Service("DoctorAccountService")
@Transactional(rollbackFor = {Throwable.class})
public class DoctorAccountServiceImpl implements DoctorAccountService {
    @Autowired
    private DoctorAccountMapper doctorAccountMapper;
    @Override
    public Integer insertDoctorAccount(DoctorAccount doctorAccount) throws BusinessException {
        List<DoctorAccount> accounts = doctorAccountMapper.selectByPhone(doctorAccount.getPhone());
        if(accounts.size()>=0){
            throw new BusinessException(ExceptionCode.DUPLICATE_PHONE);
        }
        doctorAccount.setPwd(MD5Util.encode(doctorAccount.getPwd()));
        Integer integer = doctorAccountMapper.insertDoctorAccount(doctorAccount);
        return integer;
    }
}
